import java.util.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.table.*;

abstract class card{
	private String title;		// card's name/title 
	private boolean enabled;  	// card is archived or not
	private String content;		// record the card's content
	private attachmentInfor attachmentList = null;
	protected int id = -1;
	protected int UId = -1;		//card's creator
	protected label theLabel = null;

	abstract void createNewCard(String cardName,int cardId,int createById);	// create a new card
	abstract void subscribing(String whoName);		// subscribed by whoName

	
	abstract void attachAttachmentList(attachmentInfor attachmentList); // attach file list to card
	abstract void edit();							// revise a card's content,title

	abstract void archiving();						// archive a card
	abstract void remove();							// remove a card
	abstract void unarchiving();						// unarchiving a card
	abstract void attachLabel(label theLabel);
	

	// set a card's name/title
	public void setTitle(String name){
		this.title = name;
	}
	
	// get a card's name/title
	public String getTitle(){
		return this.title;
	}
	// get how many file with the card 
	protected int getNumOfAttachmentOnTheCard(){
		if (attachmentList == null) return 0;
		return attachmentList.getAttachmentSum();
	}
	protected void setAttachment(attachmentInfor attachmentList){
		this.attachmentList = attachmentList;
	}
	// get cardId
    protected int getId(){
    	return this.id;
    }
    
    protected label getLabel(){
    	return this.theLabel;
    }
	
}

abstract class cardEditor{
	private ArrayList<card> cardList = new ArrayList<card>(); // an arrayList to store cards
	
	// to create a new card

	void createNewCard(String cardName,int cardId,int createById){

		card doc = createCard();


    	doc.createNewCard(cardName,cardId,createById);

    	cardList.add(doc);
	}
	
	// to archive specific card
	void archiving(card doc,String typeList) {
        
    }
    
	// to archive all cards on the list
    void archiving() {
        for(card doc : cardList) {
        	archiving(doc, null);
        }
    }
    
    // show all the name/title of the card on the cardList
    void getAllCardTitle(){
    	for(card doc : cardList) {
    		System.out.println("cardTitle =  " + doc.getTitle());
        }
    }
    // get how many cards in the list
    int getCardSize(){
    	int count = 0;
    	for(card doc : cardList) {
    		count++;
        }
    	return count;
    }
    
    // attach the attachmentinfo 
    void attachAttachmentList(attachmentInfor attachmentList,String cardTitle){
		for(card doc : cardList) {
			if (doc.getTitle() == cardTitle){
				doc.setAttachment(attachmentList);
				doc.attachAttachmentList(attachmentList);
            }
        }
	}
    int getNumOfAttachmentOnTheCard(String cardTitle){
		for(card doc : cardList) {
			if (doc.getTitle() == cardTitle){
            	return doc.getNumOfAttachmentOnTheCard();
            }
        }
		return 0;
	}
    ArrayList<card> getAll(){	// get all cards
    	return cardList;
    }
    
    // attach a label to the card.id = CId
    boolean attachLabel(label theLabel,int CId){
    	boolean succeed = false;
    	for (card doc : cardList){
    		if ( CId == doc.getId() ){
    			doc.attachLabel(theLabel);
    			succeed = true;
    		}
    	}
    	return succeed;
    }
    
	abstract card createCard();	// factory method
}

//  to define all the methods
class cardInfor extends cardEditor{
	card createCard() {
        return new card() {
        	void createNewCard(String cardName,int cardId,int createById){
        		setTitle(cardName);
        		this.id = cardId;
        		this.UId = createById;
        	}
        	void editCard(){
        		System.out.println("editCard " + this.getTitle());
        	}
        	void subscribing(String whoName){
        		System.out.println("subscribing " + this.getTitle() + " by " + whoName);
        	
        	}
        	void attachAttachmentList(attachmentInfor attachmentList){
        		
        		System.out.println("attach file");
        		attachmentList.getAllFileTitle();
        		System.out.println("to card " + this.getTitle());
        	}
			void edit() {
				//1
			}
			void archiving() {
				//1
			}
			void remove() {
				//1
			}
			void unarchiving() {
				//1
			}
			void attachLabel(label theLabel){
				this.theLabel = theLabel;
			}
        };	
    }
}

